package vista;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.table.AbstractTableModel;
import javax.swing.SwingUtilities;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class VentanaAgregarPersona extends javax.swing.JFrame {
	private JSplitPane jSplitPane;
	private JPanel panDatos;
	private JTextField txtNombre;
	private JLabel lblTitulo;
	private JPanel panListado;
	private JButton cmdAgregar;
	private JTextField txtCedula;
	private JLabel lblCedula;
	private JTextField txtTelefono;
	private JLabel lblTelefono;
	private JTextField txtApellido;
	private JButton cmdSalir;
	private JTable tblInvitados;
	private JScrollPane scpInvitados;
	private JLabel lblApellido;
	private JLabel lblNombre;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			@Override
			public void run() {
				VentanaAgregarPersona inst = new VentanaAgregarPersona();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public VentanaAgregarPersona() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			{
				jSplitPane = new JSplitPane();
				getContentPane().add(jSplitPane, BorderLayout.CENTER);
				{
					panDatos = new JPanel();
					jSplitPane.add(panDatos, JSplitPane.LEFT);
					panDatos.setPreferredSize(new java.awt.Dimension(329, 312));
					panDatos.setLayout(null);
					{
						lblNombre = new JLabel();
						panDatos.add(lblNombre);
						lblNombre.setText("Nombre:");
						lblNombre.setBounds(48, 89, 91, 15);
					}
					{
						txtNombre = new JTextField();
						panDatos.add(txtNombre);
						txtNombre.setBounds(156, 86, 106, 22);
					}
					{
						lblApellido = new JLabel();
						panDatos.add(lblApellido);
						lblApellido.setText("Apellido:");
						lblApellido.setBounds(48, 129, 91, 15);
					}
					{
						txtApellido = new JTextField();
						panDatos.add(txtApellido);
						txtApellido.setBounds(156, 126, 106, 22);
					}
					{
						lblTelefono = new JLabel();
						panDatos.add(lblTelefono);
						lblTelefono.setText("Telefono");
						lblTelefono.setBounds(48, 169, 96, 15);
					}
					{
						txtTelefono = new JTextField();
						panDatos.add(txtTelefono);
						txtTelefono.setBounds(156, 166, 106, 22);
					}
					{
						lblCedula = new JLabel();
						panDatos.add(lblCedula);
						lblCedula.setText("Cedula:");
						lblCedula.setBounds(48, 50, 85, 15);
					}
					{
						txtCedula = new JTextField();
						panDatos.add(txtCedula);
						txtCedula.setBounds(156, 47, 107, 22);
					}
					{
						cmdAgregar = new JButton();
						panDatos.add(cmdAgregar);
						cmdAgregar.setText("Agregar");
						cmdAgregar.setBounds(60, 236, 91, 22);
					}
					{
						cmdSalir = new JButton();
						panDatos.add(cmdSalir);
						cmdSalir.setText("Salir");
						cmdSalir.setBounds(171, 236, 91, 22);
					}
				}
				{
					panListado = new JPanel();
					jSplitPane.add(panListado, JSplitPane.RIGHT);
					panListado.setPreferredSize(new java.awt.Dimension(329, 312));
					panListado.setLayout(null);
					{
						lblTitulo = new JLabel();
						panListado.add(lblTitulo);
						lblTitulo.setText("Lista de Invitados");
						lblTitulo.setBounds(123, 28, 182, 15);
					}
					{
						scpInvitados = new JScrollPane();
						panListado.add(scpInvitados);
						scpInvitados.setBounds(17, 61, 356, 230);
						{
							tblInvitados = new JTable();
							scpInvitados.setViewportView(tblInvitados);
						}
					}
				}
			}
			this.setTitle("Agregar Invitados");
			pack();
			this.setSize(733, 341);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	public void agregarListener(ActionListener accion){
		this.cmdAgregar.addActionListener(accion);
		this.cmdSalir.addActionListener(accion);

	}
	
	public boolean datosLlenos(){
		if(this.getTxtCedula().equals("") || this.getTxtNombre().equals("") || this.getTxtApellido().equals("") || (this.getTxtTelefono().equals("")) && this.txtTelefono.isVisible() ){
			return false;
		}
		return true;
	}
	
	public String getTxtNombre() {
		return txtNombre.getText();
	}
	
	public String getTxtApellido() {
		return txtApellido.getText();
	}
	
	public String getTxtTelefono() {
		return txtTelefono.getText();
	}
	
	public String getTxtCedula() {
		return txtCedula.getText();
	}
	
	public void setListado(AbstractTableModel abstractTableModel){
		tblInvitados.setModel(abstractTableModel);
	}
	
	public void mostrarMensaje(String mensaje){
		JOptionPane.showMessageDialog(this, mensaje);
	}

	public void limpiarCampos() {
		txtApellido.setText("");
		txtCedula.setText("");
		txtNombre.setText("");
		txtTelefono.setText("");
		
	}

	public void cambiarCampos(String tipo) {
		if(tipo.equals("Anfitriones")){
			this.setTitle("Agregar Anfitriones");
			lblTelefono.setText("E-mail:");
			lblTitulo.setText("Lista de Anfitriones");
		}
		else if (tipo.equals("Agasajados")){
			this.setTitle("Agregar Agasajados");
			txtTelefono.setVisible(false);
			lblTelefono.setVisible(false);
			lblTitulo.setText("Lista de Agasajados");
		}
		
	}

}
